// pages/addOilCard/addOilCard.js
const app = getApp();
var util = require('../../utils/util.js');
Page({
  data: {
    modal: {
      toastHidden: true,
      msg: ""
    },
    bsoilCode: "",   //油卡卡号
    bsoilName: "",	//绑定姓名
    bsoilMobile: "",   //绑定手机号
    btnTxt: "提交"
  },
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  toastChange() {
    this.setData({ "modal.toastHidden": true });
  },
  bindInput(e) {
    var that = this;
    // 获取input的值
    if (e.currentTarget.dataset.id == "code") {
      this.setData({
        bsoilCode: e.detail.value
      });
    }
    if (e.currentTarget.dataset.id == "name") {
      this.setData({
        bsoilName: e.detail.value
      });
    }
    if (e.currentTarget.dataset.id == "mobile") {
      this.setData({
        bsoilMobile: e.detail.value
      });
    }
  },
  submitData() {
    var that = this;
    if (that.data.bsoilCode.length == 0 || that.data.bsoilName.length == 0 || that.data.bsoilMobile.length == 0 || that.data.bsoilMobile.length==0) {
      util.tipModal(this, "请输入完整信息！");
      return;
    }
    if (that.data.bsoilMobile.length>0 && that.data.bsoilMobile.length !== 11) {
      util.tipModal(this, "手机格式错误！");
      return;
    }
    var data = {
      bsoilUser: app.globalData.userUuid,
      bsoilCode: that.data.bsoilCode,   //油卡卡号
      bsoilName: that.data.bsoilName,	//绑定姓名
      bsoilMobile: that.data.bsoilMobile  //绑定手机号
    };
    util.requestPost("busiOil/add/busiOil", data, function (res) {
      if (res.success) {
        that.setData({ "modal.toastHidden": false, "modal.msg": '添加油卡成功' });
        debugger
      } else {
        util.tipModal(that, res.errMsg);
      }

      

      // wx.navigateTo({
      //   url: '../chooseCoupon/chooseCoupon'
      // });
    }, function (errData) {
      that.setData({ "modal.toastHidden": false, "modal.msg": '当前网格异常，请稍后再试' });
    });
  }
})